package com.ruoyi.framework.web.service;
import com.anji.captcha.service.CaptchaCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import java.util.concurrent.TimeUnit;

/**
 * 自定义redis验证码缓存实现类
 *
 * @author andy
 */
public class CaptchaRedisService implements CaptchaCacheService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public Long increment(String key, long val) {
        return redisTemplate.opsForValue().increment(key,val);
    }

    @Override
    public void set(String key, String value, long expiresInSeconds) {
        redisTemplate.opsForValue().set(key,value,expiresInSeconds, TimeUnit.SECONDS);
    }

    @Override
    public boolean exists(String key) {
        return redisTemplate.hasKey(key);
    }

    @Override
    public void delete(String key) {
        redisTemplate.delete(key);
    }

    @Override
    public String get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    @Override
    public String type() {
        return "redis";
    }
}
